package com.ganzi.ganziserver.conf.rabbit;

import com.ganzi.ganziserver.dao.ControlLogDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

public class RabbitConfirmCallback implements RabbitTemplate.ConfirmCallback{

    Logger log = LoggerFactory.getLogger(RabbitConfirmCallback.class);

    @Autowired
    ControlLogDao logdao;

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (!ack) {
            try{
                String error = "消息发送到交换机失败";
                logdao.updateControlLogStateByInfoId(2,error,correlationData.getId());
                log.info("消息发送失败,原因: {}", cause);
            }catch (Exception e){
                e.printStackTrace();
            }
        }else{
            //消息到交换机成功  仅此而已
        }
    }
}
